﻿using System;
using System.Collections.Generic;
using System.Linq;
using Model.Entity;
using Ones.Dal.Repository.Interfaces;

namespace Ones.Dal.Repository.Impl
{
    public class AdvertisementContactDao : AbstractDao<AdvertisementContact>, IAdvertisementContactDao
    {
        public override bool
        update(AdvertisementContact advContact)
        {
            try
            {
                var curr = getById(advContact.advContId);

                curr.advContName = advContact.advContName;
                curr.advContCompany = advContact.advContCompany;
                curr.advContPhone = advContact.advContPhone;

                _ctx.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public override AdvertisementContact
        getById(object id)
        {
            return getSingle(i => i.advContId == (int)id);
        }

        public List<AdvertisementContact>
        getByName(string advContName)
        {
            try
            {
                return getMultiple(i => i.advContName.Contains(advContName));
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<AdvertisementContact>
        getByCompany(string advContCompany)
        {
            try
            {
                return getMultiple(i => i.advContCompany.Contains(advContCompany));
            }
            catch (Exception)
            {
                return null;
            }
        }
    }

    #region IAdvertisementContactDao

    public interface IAdvertisementContactDao : IDao<AdvertisementContact>
    {
        List<AdvertisementContact> getByName(String advContName);

        List<AdvertisementContact> getByCompany(String advContCompany);
    }
    #endregion
}